package com.trkj.service.cf;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.trkj.dao.cf.OrganizationAreaDAO;
import com.trkj.pojo.OrganizationArea;
import com.trkj.pojo.OrganizationStructure;
import com.trkj.service.ServiceException;

@Service
@Transactional(rollbackFor=Exception.class)
public class OrganizationAreaService {
		@Autowired
		private OrganizationAreaDAO organizationAreaDAO;
	/**
	 * 组织区域
	 */
	//分页
	public List<OrganizationArea> orgareaPage(Integer page, Integer rows)throws ServiceException {
		try {
		List<OrganizationArea> list= organizationAreaDAO.queryByPage(new PageRequest(page-1,rows));
		return  list;
		} catch (Exception e) {
			e.printStackTrace();
		   throw new ServiceException(e.getMessage());
		}
	}
	//获取总记录条数
	public long pageCount() {
		return organizationAreaDAO.count();
	}
	//搜索
	public List<OrganizationArea> filedByName(String orgareaName)throws ServiceException{
			try {
				return organizationAreaDAO.queryByOrgareaName("%"+orgareaName+"%");
			} catch (Exception e) {
				e.printStackTrace();
			  throw new ServiceException(e.getMessage());
			}
	}
	//新增
	public void regionalupdate(Long orgareaId1, 
			String orgareaName, String orgareaRemark) throws ServiceException  {
			try {
					OrganizationArea org=new OrganizationArea();
					org.setOrgareaId1(orgareaId1); 
					org.setOrgareaName(orgareaName==null?"中国":orgareaName);
					org.setOrgareaRemark(orgareaRemark==null?"暂无详情":orgareaRemark);
					organizationAreaDAO.save(org);
			} catch (Exception e) {
				e.printStackTrace();
			   throw new ServiceException(e.getMessage());
			}
	}
	//删除
	public void organizationArearemove(Long orgareaId1)throws ServiceException  {
		try {
			organizationAreaDAO.delete(orgareaId1);
		} catch (Exception e) {
			e.printStackTrace();
			throw new ServiceException(e.getMessage());
		}
	}
	//编辑
	public void organizationAreaupdate(Long orgareaId1, String orgareaName, String orgareaRemark)throws ServiceException{
				try {
					System.out.println(orgareaId1);
					System.out.println(orgareaName);
					System.out.println(orgareaRemark);
					OrganizationArea org=  organizationAreaDAO.findOne(orgareaId1);
					System.out.println(org);
					org.setOrgareaName(orgareaName);
					org.setOrgareaRemark(orgareaRemark);
					organizationAreaDAO.save(org);
				} catch (Exception e) {
					e.printStackTrace();
					throw new ServiceException(e.getMessage());
				}
	}
	 
}
